from tranco import Tranco
import argparse
import yaml

def show_top(n, date_list):
    """Show top n domain name.
    """
    top_n = date_list.top(n)
    for website in top_n:
        print(website)

def get_ranking(domain, date_list):
    """if not exist, print -1.
    """
    print(date_list.rank(domain))

def main():
    parser = argparse.ArgumentParser(description="Generate DoH traffic.")

    parser.add_argument(
        "--config", "-c",
        type = str,
        default = "config.yml",
        help = "Config file path. (Default 'config.yml')")

    args = parser.parse_args()

    with open(args.config, "r") as f:
        cfg = yaml.safe_load(f.read())

        config = {
                    "DIR_TO_SAVE_TRANCO_LIST" : cfg.get("DIR_TO_SAVE_TRANCO_LIST", "data/tranco"),
                    "DATE_OF_LIST"            : cfg.get("DATE_OF_LIST", "2022.01.01"),
                }

    t = Tranco(cache=True, cache_dir=config["DIR_TO_SAVE_TRANCO_LIST"])
    date_list = t.list(date=config["DATE_OF_LIST"])

if __name__ == '__main__':
    main()
